var WxSearch = require('../../wxSearch/wxSearch.js')
var app = getApp()
Page({
  data: {
    motto: '公式大全',
    userInfo: {},
    show_info:true,
    show_data:false,
    show_button:false,
    show_search:false,
    menu:[{
      id:2,
      name:'数学',
      open:true
    },{
      id:4,
      name:'物理',
      open:false
    }],
    list: [],
    search_list:[]
  },
 
  onLoad: function () {
    var that = this;
    WxSearch.init(that,43,[]);
    if(!app.globalData.userInfo){
          wx.getUserInfo({
            success: function (res) {
              that.data.userInfo = res.userInfo;
              that.setData({userInfo:res.userInfo});
              app.globalData.userInfo = res.userInfo;
            }
          })
    }else that.setData({userInfo:app.globalData.userInfo});
    
    setTimeout(function () {
        that.setData({ show_info:false, show_data:true});
    }, 2500);

    wx.request({
        url: app.globalData.domain+'/wx/index.php',
        method:'POST',
        data: {'type': 'index'},
        header: {'Content-Type': 'application/x-www-form-urlencoded'},
        success: function(res) {
            that.setData({ list:res.data});
        }
    });


  },
  wxSearchFn: function(e){
    var that = this
    var temData = that.data.wxSearchData;
    temData.view.isShow = false;
    temData.value = '';
    that.setData({
        wxSearchData: temData,show_button:false,show_search:false,show_data:true
    });
    
  },
  wxSearchInput: function(e){
    var that = this
    WxSearch.wxSearchInput(e,that);
  },
  wxSerchFocus: function(e){   
    var that = this
    this.setData({
        show_button: true,   
    });
    WxSearch.wxSearchFocus(e,that);
  },
  wxSearchBlur: function(e){
    var that = this
    WxSearch.wxSearchBlur(e,that);
  },
  wxSearchKeyTap:function(e){
    var that = this
    WxSearch.wxSearchKeyTap(e,that);
  },
  wxSearchDeleteKey: function(e){
    var that = this
    WxSearch.wxSearchDeleteKey(e,that);
  },
  wxSearchDeleteAll: function(e){
    var that = this;
    WxSearch.wxSearchDeleteAll(that);
  },
  // wxSearchTap: function(e){
  //   var that = this
  //   widgetsToggle();
  //   //WxSearch.wxSearchHiddenPancel(that);
  // },
  widgetsToggle: function (e) {
    var id = e.currentTarget.id, list = this.data.list,menu = this.data.menu;
    if(!id) id=2;
    for (var i = 0, len = list.length; i < len; ++i) {
      if (list[i]['subject_id'] == id) {
        if( !list[i].open ){
            menu[i].open = true;
            list[i].open = true;
        }
      } else {
        list[i].open = false;
        menu[i].open = false;
      }
    }
    this.setData({
      list: list,menu:menu
    });
  },
  onShareAppMessage: function () {
    return {
      title: '公式大全小程序，查询更方便',
      desc: '快速查找公式大全与定义，随身公式小宝典。',
      path: '/page/index/index'
    }
  }

})